#!/usr/bin/ruby
# -*- ruby -*-
#
# http://www.reddit.com/r/dailyprogrammer/comments/10pf0j/9302012_challenge_102_easy_dice_roller/

ARGV.each do |d|
  a, rest = d.split(/d/)
  b, c = rest.split(/[+-]/)

  a = (! a.empty? ? a.to_i : 1)
  b = b.to_i
  c = (! c.nil? ? c.to_i : 0)
  c *= -1 if /-/.match(d)

  roll = a.times.inject(0) { |r, v| r + rand(b) + 1 } + c

  puts "#{d} : #{roll}"
end
